package com.vitabuybuy.tv.network

import com.library.common.net.NetUrl
import com.vitabuybuy.tv.dto.*


import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * 作者：SimGa
 * 日期：2020/12/29
 * 时间：15:41
 * 包名：com.vitabuybuy.tv.network
 */
object BiddingRepository {


    fun getBiddingList(
        map: HashMap<String, Any?>,
        pageNumber: Int
    ): IAwait<MutableList<BiddingListDto>> {
        map["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", 10),
            Pair("desc", "id")
        )
        return RxHttp.postJson(NetUrl.api_find_bidding_list)
            .addAll(map)
            .add("returnDescription", map)
            .toResponse()
    }

    fun getBinddingDetail(id: Int?): IAwait<BiddingDetailDto> {
        return RxHttp.postJson(NetUrl.api_find_bidding_detail)
            .add("id", id)
            .toResponse()
    }

    fun getBiddingRecord(
        biddingId: Int?,
        pageNumber: Int,
        pageSize: Int
    ): IAwait<MutableList<BiddingRecordDto>> {
        val params = HashMap<String, Any?>()
        params["biddingId"] = biddingId
        params["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", pageSize),
            Pair("desc", "id")
        )
        return RxHttp.postJson(NetUrl.api_bidding_record_list)
            .addAll(params).toResponse()
    }

    fun toBiddingjoin(
        biddingId: Int?,
        addressId: Int?,
        paymentMethod: String
    ): IAwait<String> {
        val params = HashMap<String, Any?>()
        params["id"] = biddingId
        params["address"] = mapOf(
            Pair("id", addressId)
        )
        params["paymentMethod"] = paymentMethod
        return RxHttp.postJson(NetUrl.api_bidding_join)
            .addAll(params).toResponse()
    }

    fun toAuctionBidding(
        biddingId: Int,
        price: Double
    ): IAwait<String> {
        val params = HashMap<String, Any>()
        params["biddingId"] = biddingId
        params["price"] = price
        return RxHttp.postJson(NetUrl.api_auction_bid)
            .addAll(params).toResponse()
    }

    fun toAuctionHall(
        biddingId: Int
    ): IAwait<AuctionHallDto> {
        val params = HashMap<String, Any>()
        params["id"] = biddingId
        return RxHttp.postJson(NetUrl.api_auction_hall)
            .addAll(params).toResponse()
    }


    fun getMyBiddingList(
        status: String,
        pageNumber: Int
    ): IAwait<MutableList<MyBiddingListDto>> {
        val params = HashMap<String, Any>()
        params["status"] = status
        params["pageable"] = mapOf(
            Pair("page", pageNumber),
            Pair("size", 10),
            Pair("desc", "id")
        )
        return RxHttp.postJson(NetUrl.api_my_bidding_list)
            .addAll(params).toResponse()
    }

    fun collectOrcancel(id: Int, isFav: Boolean): IAwait<String> {
        return if (!isFav) {
            RxHttp.postJson(NetUrl.api_collect_good_or_store)
                .add("favorites", mapOf(Pair("product", mapOf(Pair("id", id)))))
                .toResponse()
        } else {
            RxHttp.postJson(NetUrl.api_cancel_collect_good_or_store)
                .add("product", mapOf(Pair("id", id)))
                .toResponse()
        }
    }


    fun remindOrCancelBidding(id: Int, isRemid: Boolean): IAwait<String> {
        return RxHttp.postJson(if (isRemid) NetUrl.api_remind_bidding_cancel else NetUrl.api_remind_bidding)
            .add("id", id).toResponse()
    }
}